// 字典管理 API
import request from '@/utils/request'
import type { ApiResponse } from '@/types/api'
import type { Dictionary, DictType } from '@/types/dictionary'

/**
 * 获取某类型的字典列表（仅启用的）
 */
export function getDictionaryByType(type: DictType) {
  return request<ApiResponse<Dictionary[]>>({
    url: `/tenant/dictionary/${type}`,
    method: 'get',
  })
}

/**
 * 获取某类型的所有字典列表（包括已禁用的）
 * 用于显示历史数据
 */
export function getAllDictionaryByType(type: DictType) {
  return request<ApiResponse<Dictionary[]>>({
    url: `/tenant/dictionary/${type}/all`,
    method: 'get',
  })
}

/**
 * 获取所有字典
 */
export function getAllDictionaries() {
  return request<ApiResponse<Dictionary[]>>({
    url: '/tenant/dictionary/list',
    method: 'get',
  })
}

/**
 * 添加字典
 */
export function addDictionary(data: Partial<Dictionary>) {
  return request<ApiResponse<Dictionary>>({
    url: '/tenant/dictionary',
    method: 'post',
    data,
  })
}

/**
 * 更新字典
 */
export function updateDictionary(id: number, data: Partial<Dictionary>) {
  return request<ApiResponse<null>>({
    url: `/tenant/dictionary/${id}`,
    method: 'put',
    data,
  })
}

/**
 * 删除字典
 */
export function deleteDictionary(id: number) {
  return request<ApiResponse<null>>({
    url: `/tenant/dictionary/${id}`,
    method: 'delete',
  })
}

